package com.taotao.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.manage.pojo.ItemDesc;
import com.taotao.manage.service.ItemDescService;

/**
 * 商品描述的Controller
 * @author joedy
 * 
 */
@Controller
@RequestMapping("item/desc")
public class ItemDescController {
	
	@Autowired
	private ItemDescService itemDescService;

	/**
	 * 根据商品id查询商品描述
	 * @param itemId
	 * @return
	 */
	@GetMapping("{itemId}")
	public ResponseEntity<ItemDesc> queryItemDescById(@PathVariable("itemId")Long itemId){
		try {
			// 如果参数不合法，响应400
			if(itemId == null || itemId.longValue() <= 0){
				return ResponseEntity.badRequest().build();
			}
			// 查询商品描述
			ItemDesc itemDesc = this.itemDescService.queryById(itemId);
			if(itemDesc == null){
				// 响应404
				return ResponseEntity.notFound().build();
			}
			// 响应200
			return ResponseEntity.ok(itemDesc);
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 响应500
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
	}
}
